﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NetDon.OA.Interface;
using NetDon.OA.Interface.CRM;
using NetDon.OA.Interface.eLogistics;
using NetDon.Utilities;

namespace NetDon.OA.Portal.eLogisticsQuery
{
    [Navigation("报表查询", "营收台帐查询")]
    public partial class RevenueMachineAccountQuery : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                txtReceiptInfoActualResponseDateStart.Text =
 DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd");
                txtReceiptInfoActualResponseDateEnd.Text =
    DateTime.Now.ToString("yyyy-MM-dd");
                ddlCompany.InsertEmptyItem(ListEmptyType.Select);
                this.ddlCustomer.InsertEmptyItem(ListEmptyType.Select);
                if (!this.IsSuperRoles())
                {
                    ddlCompany.SelectedValue = CurrentApplicationContext.CompanyId.ToString();
                    ddlCompany.Enabled = false;
                }
            }
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            ObjectDataSourceCustomers.Selecting += (ds, dsArgs) =>
            {
                dsArgs.InputParameters["areaId"] = CurrentApplicationContext.CompanyId.ToString();
            };


        }
        public void ddlCustomer_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(ddlCustomer.SelectedValue))
            {

                //LoadGoodsShippedTypes(ddlCustomer.SelectedValue.ToGuid());
            }


        }

        //private void LoadGoodsShippedTypes(Guid customerId)
        //{
        //    this.ddlGoodsShippedTypeId.Items.Clear();
        //    this.ddlGoodsShippedTypeId.DataSource = ServiceContainer.GetService<ICustomerInfoService>().GetCustomerGoodsShippTypes(
        //       customerId, CurrentApplicationContext.CompanyId);
        //    this.ddlGoodsShippedTypeId.DataBind();
        //    ddlGoodsShippedTypeId.InsertEmptyItem(ListEmptyType.Select);
        //}

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            HttpContext.Current.Session["RevenueMachineAccountQuery"] = GetSearchCriteria();
            this.ScriptStartup("search();");

        }
        protected RevenueMachineAccountSearchCriteria GetSearchCriteria()
        {
            var criteria = new RevenueMachineAccountSearchCriteria
 {

 };
            if (!MiscUtilities.IsNullOrEmpty(ddlCompany.SelectedValue))
            {
                criteria.AreaId = ddlCompany.SelectedValue.ToGuid();
            }

            DateTime? dateStart = null, dateEnd = null;
            if (!string.IsNullOrEmpty(txtReceiptInfoActualResponseDateStart.Text.Trim()))
            {
                dateStart = DateTime.Parse(txtReceiptInfoActualResponseDateStart.Text.Trim());
            }
            if (!string.IsNullOrEmpty(txtReceiptInfoActualResponseDateEnd.Text.Trim()))
            {
                dateEnd = DateTime.Parse(txtReceiptInfoActualResponseDateEnd.Text.Trim());
            }
            if (dateStart.HasValue || dateEnd.HasValue)
            {
                criteria.ActualShippingDate = new Range<DateTime?>(dateStart, dateEnd);
            }



            //if (!string.IsNullOrEmpty(txtOrderCode.Text))
            //{
            //    criteria.OrderCode = txtOrderCode.Text.Trim();
            //}

            if (!string.IsNullOrEmpty(txtTransportationPlanCode.Text))
            {
                criteria.TransportationPlanCode = txtTransportationPlanCode.Text.Trim();
            }


            if (radioIsStatementofAccountNeededYes.Checked)
            {
                criteria.IsStatementofAccountCompleted = true;
            }
            else if (radioIsStatementofAccountNeededNo.Checked)
            {
                criteria.IsStatementofAccountCompleted = false;
            }


            if (radioIsInvoiceNeededYes.Checked)
            {
                criteria.IsInvoiced = true;
            }
            else if (radioIsInvoiceNeededNo.Checked)
            {
                criteria.IsInvoiced = false;
            }


            if (radioIsAccountsReceivableYes.Checked)
            {
                criteria.IsAccountsReceivable = true;
            }
            else if (radioIsAccountsReceivableNo.Checked)
            {
                criteria.IsAccountsReceivable = false;
            }
            if (!MiscUtilities.IsNullOrEmpty(ddlRouteTypeId.SelectedValue.ToGuid()))
            {
                criteria.RouteTypeId = ddlRouteTypeId.SelectedValue.ToGuid();
            }
            //if (!string.IsNullOrEmpty(ddlGoodsShippedTypeId.SelectedValue))
            //{
            //    criteria.GoodsShippedTypeId = ddlGoodsShippedTypeId.SelectedValue.ToGuid();
            //}

            if (!MiscUtilities.IsNullOrEmpty(ddlCustomer.SelectedValue.ToGuid()))
            {
                criteria.CustomerId = ddlCustomer.SelectedValue.ToGuid();
            }


            return criteria;


        }

    }
}